<html>
<head><meta charset="utf-8"><title>Check local is function parameter or not in MIR · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Check.20local.20is.20function.20parameter.20or.20not.20in.20MIR.html">Check local is function parameter or not in MIR</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="237610265"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Check%20local%20is%20function%20parameter%20or%20not%20in%20MIR/near/237610265" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hkalbasi <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Check.20local.20is.20function.20parameter.20or.20not.20in.20MIR.html#237610265">(May 06 2021 at 06:09)</a>:</h4>
<p>I'm trying to solve <a href="https://github.com/rust-lang/rust/issues/68049">https://github.com/rust-lang/rust/issues/68049</a> and this is my first experience in compiler. A wrong suggestion is here and we know local in MIR. I want to check if this local is belong to a function parameter and if that that function is in impl of a trait, then disable the suggestion because changing signature of impl trait is meaningless (if I succeed I will try to find that trait and move suggestion there instead of disabling it completely) how I can do that?</p>



<a name="237696620"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Check%20local%20is%20function%20parameter%20or%20not%20in%20MIR/near/237696620" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Check.20local.20is.20function.20parameter.20or.20not.20in.20MIR.html#237696620">(May 06 2021 at 17:21)</a>:</h4>
<p><span class="user-mention" data-user-id="401078">@hkalbasi</span>: The first step is to find out where that error is being emitted. Have you built a local stage1 <code>rustc</code>?</p>



<a name="237740849"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Check%20local%20is%20function%20parameter%20or%20not%20in%20MIR/near/237740849" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hkalbasi <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Check.20local.20is.20function.20parameter.20or.20not.20in.20MIR.html#237740849">(May 06 2021 at 22:32)</a>:</h4>
<p><span class="user-mention" data-user-id="125294">@Aaron Hill</span> Yes I have a local build and I know the wrong suggestion is emitted <a href="https://github.com/rust-lang/rust/blob/377d1a984cd2a53327092b90aa1d8b7e22d1e347/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs#L427">here</a></p>



<a name="237741280"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Check%20local%20is%20function%20parameter%20or%20not%20in%20MIR/near/237741280" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hkalbasi <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Check.20local.20is.20function.20parameter.20or.20not.20in.20MIR.html#237741280">(May 06 2021 at 22:37)</a>:</h4>
<p>There is an <code>is_user_variable</code> function but there isn't an <code>is_function_parameter</code> variable. Maybe MIR is too late to find it out and make a helpful suggestion?</p>



<a name="237741589"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Check%20local%20is%20function%20parameter%20or%20not%20in%20MIR/near/237741589" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Check.20local.20is.20function.20parameter.20or.20not.20in.20MIR.html#237741589">(May 06 2021 at 22:41)</a>:</h4>
<p><span class="user-mention" data-user-id="401078">@hkalbasi</span> I think the easiest way of getting that information would be to add a field to <code>VarBindingForm</code></p>



<a name="237741704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Check%20local%20is%20function%20parameter%20or%20not%20in%20MIR/near/237741704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Check.20local.20is.20function.20parameter.20or.20not.20in.20MIR.html#237741704">(May 06 2021 at 22:42)</a>:</h4>
<p>You can then set that field when a <code>VarBindingForm</code> gets created for a function argument: <a href="https://github.com/rust-lang/rust/blob/676ee14729462585b969bbc52f32c307403f4126/compiler/rustc_mir_build/src/build/mod.rs#L1000-L1005">https://github.com/rust-lang/rust/blob/676ee14729462585b969bbc52f32c307403f4126/compiler/rustc_mir_build/src/build/mod.rs#L1000-L1005</a></p>



<a name="237765620"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Check%20local%20is%20function%20parameter%20or%20not%20in%20MIR/near/237765620" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hkalbasi <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Check.20local.20is.20function.20parameter.20or.20not.20in.20MIR.html#237765620">(May 07 2021 at 04:06)</a>:</h4>
<p>Looks good! The next step is figuring out which function is it and whether this function is part of impl of a trait or not. I think it can not added to <code>VarBindingForm</code> (I want to add a bool field) because there are cases such as <code>ImplicitSelf</code> that are not <code>Var</code> but the function should be find. I think I should convert <code>LocalDecl</code> to hir but I don't know how.</p>



<a name="237765781"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Check%20local%20is%20function%20parameter%20or%20not%20in%20MIR/near/237765781" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hkalbasi <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Check.20local.20is.20function.20parameter.20or.20not.20in.20MIR.html#237765781">(May 07 2021 at 04:08)</a>:</h4>
<p><span class="user-mention" data-user-id="125294">@Aaron Hill</span></p>



<a name="237912232"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Check%20local%20is%20function%20parameter%20or%20not%20in%20MIR/near/237912232" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hkalbasi <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Check.20local.20is.20function.20parameter.20or.20not.20in.20MIR.html#237912232">(May 08 2021 at 01:11)</a>:</h4>
<p>By the way there was a <code>Body::local_kind</code> function so I didn't need to add a field to <code>VarBindingForm</code>. But still I'm blocked on figuring out what function is the current scope function.</p>



<a name="237931942"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Check%20local%20is%20function%20parameter%20or%20not%20in%20MIR/near/237931942" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hkalbasi <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Check.20local.20is.20function.20parameter.20or.20not.20in.20MIR.html#237931942">(May 08 2021 at 06:50)</a>:</h4>
<p>Seems I found it. <code>MirSource</code> looks useful.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>